﻿using System;
using SharpSqlAnalyzer.stmt;

namespace SharpSqlAnalyzer.nodes
{
	// Token: 0x020002B1 RID: 689
	public class TCTE : TParseTreeNode
	{
		// Token: 0x06001752 RID: 5970 RVA: 0x00327DA0 File Offset: 0x00325FA0
		public void setColumnList(TObjectNameList cl)
		{
			this.columnList = cl;
		}

		// Token: 0x06001753 RID: 5971 RVA: 0x00327DAC File Offset: 0x00325FAC
		public virtual bool searchColumnInResultSet(TCustomSqlStatement pSql, TTable pTable, TObjectName pColumn, bool pMustIn)
		{
			bool flag = false;
			if (this.ColumnList != null)
			{
				for (int i = 0; i < this.ColumnList.size(); i++)
				{
					flag = this.ColumnList.getObjectName(i).ToString().Equals(pColumn.ColumnNameOnly, StringComparison.CurrentCultureIgnoreCase);
					if (flag)
					{
						break;
					}
				}
				return flag;
			}
			for (TCustomSqlStatement tcustomSqlStatement = pSql; tcustomSqlStatement != null; tcustomSqlStatement = tcustomSqlStatement.ParentStmt)
			{
				if (tcustomSqlStatement == this.Subquery)
				{
					pTable.LinkedColumns.addObjectName(pColumn);
					pColumn.SourceTable = pTable;
					flag = true;
					break;
				}
			}
			return flag || (this.Subquery != null && this.Subquery.searchColumnInResultSet(pColumn, pMustIn));
		}

		// Token: 0x170004D6 RID: 1238
		// (get) Token: 0x06001754 RID: 5972 RVA: 0x00327E4C File Offset: 0x0032604C
		// (set) Token: 0x06001755 RID: 5973 RVA: 0x00327EBC File Offset: 0x003260BC
		public virtual TCustomSqlStatement PreparableStmt
		{
			get
			{
				this.preparableStmt = null;
				if (this.subquery != null)
				{
					this.preparableStmt = this.subquery;
				}
				else if (this.updateStmt != null)
				{
					this.preparableStmt = this.updateStmt;
				}
				else if (this.deleteStmt != null)
				{
					this.preparableStmt = this.deleteStmt;
				}
				else if (this.insertStmt != null)
				{
					this.preparableStmt = this.insertStmt;
				}
				return this.preparableStmt;
			}
			set
			{
				this.preparableStmt = value;
			}
		}

		// Token: 0x170004D7 RID: 1239
		// (get) Token: 0x06001756 RID: 5974 RVA: 0x00327EC5 File Offset: 0x003260C5
		// (set) Token: 0x06001757 RID: 5975 RVA: 0x00327ECD File Offset: 0x003260CD
		public virtual TUpdateSqlStatement UpdateStmt
		{
			get
			{
				return this.updateStmt;
			}
			set
			{
				this.updateStmt = value;
			}
		}

		// Token: 0x170004D8 RID: 1240
		// (get) Token: 0x06001758 RID: 5976 RVA: 0x00327ED6 File Offset: 0x003260D6
		// (set) Token: 0x06001759 RID: 5977 RVA: 0x00327EDE File Offset: 0x003260DE
		public virtual TInsertSqlStatement InsertStmt
		{
			get
			{
				return this.insertStmt;
			}
			set
			{
				this.insertStmt = value;
			}
		}

		// Token: 0x170004D9 RID: 1241
		// (get) Token: 0x0600175A RID: 5978 RVA: 0x00327EE7 File Offset: 0x003260E7
		// (set) Token: 0x0600175B RID: 5979 RVA: 0x00327EEF File Offset: 0x003260EF
		public virtual TDeleteSqlStatement DeleteStmt
		{
			get
			{
				return this.deleteStmt;
			}
			set
			{
				this.deleteStmt = value;
			}
		}

		// Token: 0x170004DA RID: 1242
		// (get) Token: 0x0600175C RID: 5980 RVA: 0x00327EF8 File Offset: 0x003260F8
		// (set) Token: 0x0600175D RID: 5981 RVA: 0x00327F00 File Offset: 0x00326100
		public virtual TObjectName TableName
		{
			get
			{
				return this.tableName;
			}
			set
			{
				this.tableName = value;
			}
		}

		// Token: 0x170004DB RID: 1243
		// (get) Token: 0x0600175F RID: 5983 RVA: 0x00327F12 File Offset: 0x00326112
		// (set) Token: 0x0600175E RID: 5982 RVA: 0x00327F09 File Offset: 0x00326109
		public virtual TObjectNameList ColumnList
		{
			get
			{
				return this.columnList;
			}
			set
			{
				this.columnList = value;
			}
		}

		// Token: 0x170004DC RID: 1244
		// (get) Token: 0x06001760 RID: 5984 RVA: 0x00327F1A File Offset: 0x0032611A
		// (set) Token: 0x06001761 RID: 5985 RVA: 0x00327F22 File Offset: 0x00326122
		public virtual TSelectSqlStatement Subquery
		{
			get
			{
				return this.subquery;
			}
			set
			{
				this.subquery = value;
			}
		}

		// Token: 0x06001762 RID: 5986 RVA: 0x00327F2C File Offset: 0x0032612C
		public override void init(object arg1, object arg2)
		{
			this.tableName = (TObjectName)arg1;
			this.tableName.ObjectType = 5;
			if (arg2 is TSelectSqlNode)
			{
				this.selectNode = (TSelectSqlNode)arg2;
				if (this.selectNode.ParenthesisCount == 0)
				{
					this.selectNode.incParenthesisCount();
					return;
				}
			}
			else
			{
				if (arg2 is TInsertSqlNode)
				{
					this.insertSqlNode = (TInsertSqlNode)arg2;
					return;
				}
				if (arg2 is TUpdateSqlNode)
				{
					this.updateSqlNode = (TUpdateSqlNode)arg2;
					return;
				}
				if (arg2 is TDeleteSqlNode)
				{
					this.deleteSqlNode = (TDeleteSqlNode)arg2;
				}
			}
		}

		// Token: 0x06001763 RID: 5987 RVA: 0x00327FBC File Offset: 0x003261BC
		public override void doParse(TCustomSqlStatement psql, ESqlClause plocation)
		{
			if (this.selectNode != null)
			{
				this.subquery = new TSelectSqlStatement(psql.dbvendor);
				this.subquery.rootNode = this.selectNode;
				this.subquery.QueryOfCTE = true;
				this.subquery.doParseStatement(psql);
				return;
			}
			if (this.insertSqlNode != null)
			{
				this.insertStmt = new TInsertSqlStatement(psql.dbvendor);
				this.insertStmt.rootNode = this.insertSqlNode;
				this.insertStmt.doParseStatement(psql);
				return;
			}
			if (this.deleteSqlNode != null)
			{
				this.deleteStmt = new TDeleteSqlStatement(psql.dbvendor);
				this.deleteStmt.rootNode = this.deleteSqlNode;
				this.deleteStmt.doParseStatement(psql);
				return;
			}
			if (this.updateSqlNode != null)
			{
				this.updateStmt = new TUpdateSqlStatement(psql.dbvendor);
				this.updateStmt.rootNode = this.updateSqlNode;
				this.updateStmt.doParseStatement(psql);
			}
		}

		// Token: 0x06001764 RID: 5988 RVA: 0x003280B4 File Offset: 0x003262B4
		public override void accept(TParseTreeVisitor v)
		{
			v.preVisit(this);
			v.postVisit(this);
		}

		// Token: 0x06001765 RID: 5989 RVA: 0x003280C4 File Offset: 0x003262C4
		public override void acceptChildren(TParseTreeVisitor v)
		{
			v.preVisit(this);
			v.postVisit(this);
		}

		// Token: 0x040017FF RID: 6143
		private TSelectSqlNode selectNode;

		// Token: 0x04001800 RID: 6144
		private TSelectSqlStatement subquery;

		// Token: 0x04001801 RID: 6145
		private TInsertSqlNode insertSqlNode;

		// Token: 0x04001802 RID: 6146
		private TInsertSqlStatement insertStmt;

		// Token: 0x04001803 RID: 6147
		private TUpdateSqlNode updateSqlNode;

		// Token: 0x04001804 RID: 6148
		private TUpdateSqlStatement updateStmt;

		// Token: 0x04001805 RID: 6149
		private TDeleteSqlNode deleteSqlNode;

		// Token: 0x04001806 RID: 6150
		private TDeleteSqlStatement deleteStmt;

		// Token: 0x04001807 RID: 6151
		private TCustomSqlStatement preparableStmt;

		// Token: 0x04001808 RID: 6152
		private TObjectName tableName;

		// Token: 0x04001809 RID: 6153
		private TObjectNameList columnList;
	}
}
